<?php

namespace App\Http\Controllers\web;

use App\Http\Controllers\Controller;
use App\Http\Service\EncryptionService;
use App\Http\Service\QRcodeService;
use App\Models\StoreOrder;
use App\Repository\RepositoryInterface\ProductBoundInterface;
use Illuminate\Http\Request;



//商品自提
//苑立彬
class ProductBoundController extends Controller
{
    //
    protected $productBound;

    public function __construct(ProductBoundInterface $productBound)
    {
        $this->productBound = $productBound;
    }

    /**
     * $id 订单id
     * $status 订单状态
     * @param Request $request
     * @return array|\Illuminate\Http\JsonResponse
     */
    public function statusUpdate(Request $request)
    {
        $id = $request->post('id');
        $status = $request->post('status');

        try {
            $this->productBound->status($id, $status);

            return parent::success('修改成功');
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 生成二维码
     */
    public function index($uid)
    {
        try {

            //加密
            $uid = EncryptionService::passport_encrypt($uid, config('encryption.key'));

            $result = QRcodeService::QrCode($uid);
            return $result;
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }





    /**
     * 订单
     * 提货页面
     * @param $id
     * @return mixed
     */
    public function order($id)
    {
        try {
            $orderInfo = $this->productBound->goods($id);
            $orderInfo = json_decode($orderInfo, true);
            return view('/order', compact('orderInfo', 'id'));
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }


    }

    /**
     * 提货
     * @param $id
     */
    public function receivingGoods($id)
    {

        try {
            $result = $this->productBound->delivery($id);

            if ($result) {
                return parent::success('查询成功', "$result");
            }
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }


    }

    /**
     * 订单后台
     * @return array|\Illuminate\Http\JsonResponse
     */
    public function dist()
    {
        try {
            $data = $this->productBound->orderList();
            return parent::success('查询成功', $data);
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }


    }


}
